﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SDMX_Common = SDMX_ML.Framework.Common;

namespace SDMX_ML.Framework.Structure
{
    /// <summary>
    /// HierarchyType.
    /// </summary>
    public class HierarchyType
    {
        
        private List<SDMX_Common.TextType> _name;
        private string _validFrom;
        private string _validTo;
        private List<SDMX_Common.TextType> _description;
        private List<CodeRefType> _codeRef;
        private List<LevelType> _level;
        private SDMX_Common.AnnotationsType _annotations;
        private SDMX_Common.IDType _id;
        private string _urn;
        private string _version;
        private bool? _isFinal;

        /// <summary>
        /// HierarchyType.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        public HierarchyType(SDMX_Common.TextType name, SDMX_Common.IDType id)
        {
            if (name != null & id != null)
            {
                if (!String.IsNullOrEmpty(name.Text))
                {
                    _name = new List<SDMX_Common.TextType>();
                    _description = new List<SDMX_Common.TextType>();
                    _codeRef = new List<CodeRefType>();
                    _level = new List<LevelType>();

                    _name.Add(name);
                }
                else
                {
                    throw new Exception("Text in element name is missing.");
                }

                if (!String.IsNullOrEmpty(id.Value))
                {
                    _id = id;
                }
                else
                {
                    throw new Exception("Value in attribute id is missing.");
                }
            }
            else
            {
                throw new Exception("Element Name and attribute id are required in HierarchyType.");
            }
        }

        //Elements

        /// <summary>
        /// Name.
        /// </summary>
        public List<SDMX_Common.TextType> Name
        {
            get { return _name; }
            set { _name = value; }
        }
 
        /// <summary>
        /// Description.
        /// </summary>
        public List<SDMX_Common.TextType> Description
        {
            get { return _description; }
            set { _description = value; }
        }
 
        /// <summary>
        /// CodeRef.
        /// </summary>
        public List<CodeRefType> CodeRef
        {
            get { return _codeRef; }
            set { _codeRef = value; }
        }
  
        /// <summary>
        /// Level.
        /// </summary>
        public List<LevelType> Level
        {
            get { return _level; }
            set { _level = value; }
        }
        
        /// <summary>
        /// Annotations.
        /// </summary>
        public SDMX_Common.AnnotationsType Annotations
        {
            get { return _annotations; }
            set { _annotations = value; }
        }

        //Attributes
         public SDMX_Common.IDType Id
        {
            get { return _id; }
            set { _id = value; }
        }
        
        /// <summary>
        /// Urn.
        /// </summary>
        public string Urn
        {
            get { return _urn; }
            set { _urn = value; }
        }
        
        /// <summary>
        /// Version.
        /// </summary>
        public string Version
        {
            get { return _version; }
            set { _version = value; }
        }
 
        /// <summary>
        /// IsFinal.
        /// </summary>
        public bool? IsFinal
        {
            get { return _isFinal; }
            set { _isFinal = value; }
        }
        
        /// <summary>
        /// ValidFrom.
        /// </summary>
        public string ValidFrom
        {
            get { return _validFrom; }
            set { _validFrom = value; }
        }

        /// <summary>
        /// ValidTo.
        /// </summary>
        public string ValidTo
        {
            get { return _validTo; }
            set { _validTo = value; }
        }
    }
}
